﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SMSQuickSend.aspx.cs" Inherits="Hello_World.SMSQuickSend" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

 <form method="post" id="form1" name="form1" action="../../../team/wsc/Pro/SMS/SMSLib/SMSMVC\SMSInfo\QuickSend">
<fieldset>
<legend>快速发送</legend>
    <div id="body"> 
           <div id="sendphones">              
                     <table  class="table">                       
                         <tr><th colspan="4">
                         <div style="float:left" >手机号码列表</div>
                         <div id="phonesmessage" style="float:right; width:30px"></div>&nbsp;
                         </th></tr>
                     <tr><td> <%= Html.TextArea("phonesContent", null, new { @Style = "width:100%;height:300px;" })%>  
                        </td></tr>
                     </table>
               </div>                                
           <div id="sendcontent">  
                     <table class="table">
                     <tr><th colspan="4">
                         <div style="float:left" >短信内容</div>
                         <div style="float:right" id="SmsContentlengh"></div> 
                         </th></tr>
                     <tr><td colspan="4">
                      <%= Html.TextArea("SmsContent", null, new { @Style = " width:100%;height:140px;" })%>                     
                     </td></tr>
                       <tr><th>
                         短信签名:
                         </th><td colspan="3">
                          <%= Html.TextBox("Signature", null, new { @Style = " width:100%;" })%>
                         </td></tr>
                         <tr><th style=" width:80px">
                         项目编号:
                         </th><td  style=" width:120px">
                             <%= Html.TextBox("txtProjectNo",null,new{@Style = " width:95%;" })%>
                         </td><th style=" width:80px">
                         查询编号:
                         </th><td style=" width:120px">
                              <%= Html.TextBox("QueryID",null,new{@Style = " width:100%;"})%>
                         </td></tr>              
                          <tr><th>
                         备注:
                         </th><td colspan="3">
                                  <%= Html.TextBox("Remarks", null, new { @Style = " width:100%;"  })%>
                              </td></tr>
                          <tr><th>
                         发送通道:
                         </th><td colspan="3" align="left">               
                                <div style="float:left"> <%= Html.DropDownList("operators", TempData["ChannelID"] as SelectList)%></div>
                              <div style="float:left">剩余 </div>
                               <div style="float:left" id="lastRecord"><%=TempData["lastRecord"]%> </div>   
                                <div style="float:left">条</div>                        
                              </td></tr>
                         <tr><td colspan="4">  <div id="search">
                            <input type="reset" name="test" value="清空" onclick= "return IsReset();"/>&nbsp;&nbsp;&nbsp;
                            <input type="submit" name="test" value="测试发送" onclick="return IsSend();" />&nbsp;&nbsp;&nbsp;
                             <input type="submit" name="send" value="正式发送" onclick="return IsSend();"/>
                             </div>
                             </td></tr>
                     </table>                 
                 </div> 
           <div id="diverrorphones">
                 <table class="table">
                     <tr><th colspan="4">异常手机号码</th></tr>
                     <tr><td><%= Html.TextArea("errorphones", null, new { @Style = " width:100%;height:300px;" })%></td></tr>
                     </table>
                 </div>
    </div>
 </fieldset>
</form>
<script type="text/javascript" language="javascript">

    $.getJSON("/SMSInfo/GetChannelIDRecord", {
        caseTypeCategoryId: $("#operators option:selected").val()
    },
           function (data) {
               document.getElementById("lastRecord").innerHTML = data.toString();
           });

</script>

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $("#diverrorphones").hide();
        TextAreaRow();
        TextArealeng();
        $("#operators").change(function () {
            $.getJSON("/SMSInfo/GetChannelIDRecord", {
                caseTypeCategoryId: $("#operators option:selected").val()
            },
           function (data) {
               document.getElementById("lastRecord").innerHTML = data.toString();
           });
        });
        $("#Signature").keyup(function () {
            TextArealeng();
        });
        $("#SmsContent").keyup(function () {
            TextArealeng();
        });
        $("#phonesContent").keyup(function () {
            TextAreaRow();
        });
        $("#phonesContent").change(function () {
            TextAreaRow();
        });

    });
    //发送时调用 
    function IsSend() {
        if ($.trim($("#phonesContent").val()) == "") {
            alert("手机号码 不可以为空！");
            $("#phonesContent").focus();
            return false;
        }
        if ($.trim($("#SmsContent").val()) == "") {
            alert("短信内容 不可以为空！");
            $("#SmsContent").focus();
            return false;
        }
        if ($.trim($("#SmsContent").val()).length + $.trim($("#Signature").val()).length > 256) {
            alert("短信内容 字符太多 ！");
            $("#SmsContent").focus();
            return false;
        }
        if ($.trim($("#txtProjectNo").val()) == "") {
            alert("项目编号 不可以为空！");
            $("#txtProjectNo").focus();
            return false;
        }
        if ($.trim($("#txtProjectNo").val()).length > 50) {
            alert("项目编号 字符太多 ！");
            $("#txtProjectNo").focus();
            return false;
        }
        if ($.trim($("#QueryID").val()) == "") {
            alert("查询编号 不可以为空！");
            $("#QueryID").focus();
            return false;
        }
        if ($.trim($("#QueryID").val()).length > 50) {
            alert("查询编号 字符太多 ！");
            $("#QueryID").focus();
            return false;
        }
        //手机号码 不规范
        if ($.trim($("#phonesContent").val()) != "") {
            var allphone = $("#phonesContent").val().toString();
            var phonesArray = "";
            var errorphones = "";
            var enmp;
            var reg = /(^\w{1,10}\s*$)|(^\w{12,}\s*$)|(^1[0,1,2,4,9]\w+\s*$)/gm;
            var phones = allphone.replace(reg, '');
            var phonesmatch = phones.match(/^\d{11}$/gm);
            var results = allphone.match(reg);
            if (results != null) {
                for (var i = 0; i < results.length; i++) {
                    errorphones += (results[i] + "\r\n");
                }
            }
            phonesArray = $.trim(phonesmatch).replace(/,/g, "\r\n");
            document.getElementById("phonesContent").value = phonesArray;
            if ($.trim(errorphones) != "") {
                $("#diverrorphones").show();
                document.getElementById("errorphones").value = errorphones;
                alert("手机号码 不规范");
                $("#phonesContent").focus();
                TextAreaRow();
                return false;
            }
        }
        if (parseInt(document.getElementById("phonesmessage").innerHTML) > parseInt(document.getElementById("lastRecord").innerHTML)) {
            alert("通道余额不足！");
            return false;
        }
        if (confirm("您确定要发送吗？")) {
            return true;
        }
        return false;
    }

    //手机个数
    function TextAreaRow() {
        var obj = document.getElementById("phonesContent").innerHTML.split("\n").length;
        if ($("#phonesContent").val() == "") {
            document.getElementById("phonesmessage").innerHTML = 0;
        } else {
            document.getElementById("phonesmessage").innerHTML = obj;
        }
    }
    //短信字数
    function TextArealeng() {
        document.getElementById("SmsContentlengh").innerHTML = "您已经输入了" + ($.trim($("#SmsContent").val()).length + getSignatureLength()) + "个字";
    }
    //发送时调用 
    function IsReset() {

        for (var i = 0; i < form1.elements.length; i++) {
            if (form1.elements(i).type == 'TextBox') {
                form1.elements(i).value = "";
            }
            if (form1.elements(i).type == 'text') {
                form1.elements(i).value = "";
            }
            if (form1.elements(i).type == 'textarea') {
                form1.elements(i).value = "";
            }
        }
        return false;
    }
    //短信签名长度加2
    function getSignatureLength() {
        if ($.trim($("#Signature").val()).length == 0) {
            return 0;
        } else {
            return $.trim($("#Signature").val()).length + 2; //加[]两个字符
        }
    }
    //字符长度
    function getStrLength(str) {
        if (str == null) { return 0 };
        var realLength = 0, len = str.length, charCode = -1;
        for (var i = 0; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128) realLength += 1;
            else realLength += 2;
        }
        return realLength;
    };

</script>
</asp:Content>
